package com.spring.demo1.eg1;

/**
 * @author vhans
 */
public class MainConfig1 {

    public static void main(String[] args) {
        //创建serviceA
        ServiceA serviceA = new ServiceA();
        //创建serviceB
        ServiceB serviceB = new ServiceB();
        //将serviceA注入到serviceB中
        serviceB.setServiceA(serviceA);
        //将serviceB注入到serviceA中
        serviceA.setServiceB(serviceB);

        System.out.println(serviceA);
        System.out.println(serviceA.getServiceB());
        System.out.println(serviceB);
        System.out.println(serviceB.getServiceA());

        /*
        1.spring轮询准备创建2个bean：serviceA和serviceB
        2.spring容器发现singletonObjects中没有serviceA
        3.调用serviceA的构造器创建serviceA实例
        4.serviceA准备注入依赖的对象，发现需要通过setServiceB注入serviceB
        5.serviceA向spring容器查找serviceB
        6.spring容器发现singletonObjects中没有serviceB
        7.调用serviceB的构造器创建serviceB实例
        8.serviceB准备注入依赖的对象，发现需要通过setServiceA注入serviceA
        9.serviceB向spring容器查找serviceA
        10.此时又进入步骤2了
         */
    }
}
